package com.luomu.base.biz.cookBook.simple.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.luomu.base.api.bo.RspPage;
import com.luomu.base.api.constant.BaseRspConstants;
import com.luomu.base.api.cookBook.simple.bo.FinanceArApAndInvoiceInfoBO;
import com.luomu.base.api.cookBook.simple.bo.FinanceArApAndInvoiceInfoReqBO;
import com.luomu.base.api.cookBook.simple.service.FinanceArApAndInvoiceInfoService;
import com.luomu.base.biz.cookBook.simple.dao.FinanceArApAndInvoiceInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* @author Luomu
* @description 针对表【t_finance_ar_ap_and_invoice_info】的数据库操作Service实现
* @createDate 2025-02-14 15:42:59
*/
@Slf4j
@RestController
@RequestMapping("/financeArApAndInvoiceInfoService")
public class FinanceArApAndInvoiceInfoServiceImpl implements FinanceArApAndInvoiceInfoService {

    @Autowired
    private FinanceArApAndInvoiceInfoMapper financeArApAndInvoiceInfoMapper;


    @Override
    public RspPage<FinanceArApAndInvoiceInfoBO> queryFinanceArApAndInvoiceInfoList(@RequestBody FinanceArApAndInvoiceInfoReqBO financeArApAndInvoiceInfoBO){
        RspPage<FinanceArApAndInvoiceInfoBO> rspPage = new RspPage<>();
        Page<Map<String, Object>> page = new Page<Map<String, Object>>(financeArApAndInvoiceInfoBO.getPageNo(),financeArApAndInvoiceInfoBO.getPageSize());

        if(!Objects.equals(financeArApAndInvoiceInfoBO.getOrgId(),104577L)){
            return rspPage;
        }

        // 发票号码
        if(StringUtils.isNotBlank(financeArApAndInvoiceInfoBO.getInvoiceNumber())){
            String[] split = financeArApAndInvoiceInfoBO.getInvoiceNumber().trim().split(",|，");
            financeArApAndInvoiceInfoBO.setInvoiceNumbers(Arrays.asList(split));
        }

        List<FinanceArApAndInvoiceInfoBO> list = financeArApAndInvoiceInfoMapper.queryFinanceArApAndInvoiceInfoList(financeArApAndInvoiceInfoBO,page);

        log.info("查询应付单信息：{}", JSONObject.toJSONString(list));

        rspPage.setPageNo(financeArApAndInvoiceInfoBO.getPageNo());
        rspPage.setRows(list);
        rspPage.setTotal(page.getTotal());
        rspPage.setCode(BaseRspConstants.RSP_CODE_SUCCESS);
        rspPage.setMessage(BaseRspConstants.RSP_DESC_SUCCESS);

        return rspPage;
    }
}




